package fr.upmc.i3s.upmcontact.tools;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class DateUtils {
	
	public static String toDisplayDate(Date date) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
		return dateFormat.format(date);
	}
	
	public static String toDisplayTime(Date date) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm", Locale.getDefault());
		return dateFormat.format(date);
	}
	
	public static String toDisplayDateTime(Date date) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy - HH:mm", Locale.getDefault());
		return dateFormat.format(date);
	}
	
	public static String toDisplayDateTime(long dateMs) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy - HH:mm", Locale.getDefault());
		return dateFormat.format(new Date(dateMs));
	}
	
	public static boolean isTodayBefore(Date date) {
		return new Date(System.currentTimeMillis()).before(date);
	}
	
	public static boolean isTodayAfter(Date date) {
		return new Date(System.currentTimeMillis()).after(date);
	}
	
	public static boolean isTodayInto(Date begin, Date end) {
		return isIntoPeriod(new Date(System.currentTimeMillis()), begin, end);
	}
	
	public static boolean isIntoPeriod(Date date, Date begin, Date end) {
		if(date.after(begin) && date.before(end)) {
			return true;
		}
		return false;
	}
	
	public static int getDaysNumber(Date start, Date end) {
		return (int)( (end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
	}
	
	public static Date today() {
		return new Date(System.currentTimeMillis());
	}
}
